<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Calendar
 * @subpackage Event_Render_ZendView
 * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id$
 */

/**
 * Zend_Calendar_Event_Render_ZendView
 *
 * @category   Zend
 * @package    Zend_Calendar
 * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Calendar_Render_ZendView extends Zend_Calendar_Render_Abstract implements 
	Zend_Calendar_Render_Interface
{
	protected $_template = null;
	protected $_scriptPath = null;
	
	public function init(array $options = array())
	{
		if (isset($options['viewScript'])) {
			$this->setTemplate($options['viewScript']);
		} else {
			$this->setTemplate('calendar.phtml');
		}
		
		if (isset($options['scriptPath'])) {
			$this->setScriptPath($options['scriptPath']);
		} else {
			$this->setScriptPath(APPLICATION_PATH . '/views/layouts/');
		}
	}
	
	public function setScriptPath($scriptPath)
	{
		$this->_scriptPath = $scriptPath;
		return $this;
	}
	
	public function setTemplate($templateName)
	{
		$this->template = $templateName;
		return $this;
	}
	
	public function getScriptPath()
	{
		return $this->_scriptPath;
	}
	
	public function getTemplate()
	{
		return $this->template;
	}
	
	public function render()
	{
		if (!$templateName = $this->getTemplate()) {
			return '';
		}
		
		$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
		$view = clone $viewRenderer->view;
		$view->clearVars();
		$view->calendar = $this->getCalendar();
		$view->baseUrl = Zend_Controller_Front::getInstance()->getRequest()->getBaseUrl();
		$view->addScriptPath($this->getScriptPath());
		
		return $view->render($templateName);
	}
}